package org.zhadoop.stream.cql.semanticanalyzer.parser.visitor;

import java.util.Locale;

import org.antlr.v4.runtime.misc.NotNull;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.ExpressionContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.CQLParser.PrimitiveTypeContext;
import org.zhadoop.stream.cql.semanticanalyzer.parser.context.CastExpressionContext;
import org.zhadoop.streaming.util.StreamingDataType;

/**
 * cast 表达式语法遍历
 * 
 * @author zwd
 *
 */
public class CastExpressionVisitor extends AbsCQLParserBaseVisitor<CastExpressionContext> {

	private CastExpressionContext context = null;

	public CastExpressionVisitor() {
		context = new CastExpressionContext();
	}

	@Override
	protected CastExpressionContext defaultResult() {
		return context;
	}

	@Override
	public CastExpressionContext visitExpression(ExpressionContext ctx) {
		ExpressionVisitor visitor = new ExpressionVisitor();
		context.setExpression(visitor.visit(ctx));
		return context;
	}

	@Override
	public CastExpressionContext visitPrimitiveType(@NotNull PrimitiveTypeContext ctx) {
		context.setDatatype(StreamingDataType.valueOf(ctx.getText().toUpperCase(Locale.US)));
		return super.visitPrimitiveType(ctx);
	}

}
